import java.util.regex.Pattern;

// 创意标题匹配
public class TitleMatching {
    public static String solution(int n, String template, String[] titles) {
        // 将模板转换为正则表达式
        String regex = template.replaceAll("\\{[^}]*\\}", ".*");
        Pattern pattern = Pattern.compile("^" + regex + "$");
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < n; i++) {
            boolean match = pattern.matcher(titles[i]).matches();
            result.append(match ? "True" : "False");
            if (i < n - 1) {
                result.append(",");
            }
        }
        // System.out.println(result.toString());
        return result.toString();
    }

    public static void main(String[] args) {
        //  You can add more test cases here
        String[] testTitles1 = {"adcdcefdfeffe", "adcdcefdfeff", "dcdcefdfeffe", "adcdcfe"};
        String[] testTitles2 = {"CLSomGhcQNvFuzENTAMLCqxBdj", "CLSomNvFuXTASzENTAMLCqxBdj", "CLSomFuXTASzExBdj", "CLSoQNvFuMLCqxBdj", "SovFuXTASzENTAMLCq", "mGhcQNvFuXTASzENTAMLCqx"};
        String[] testTitles3 = {"abcdefg", "abefg", "efg"};

        System.out.println(solution(4, "ad{xyz}cdc{y}f{x}e", testTitles1).equals("True,False,False,True"));
        System.out.println(solution(6, "{xxx}h{cQ}N{vF}u{XTA}S{NTA}MLCq{yyy}", testTitles2).equals("False,False,False,False,False,True"));
        System.out.println(solution(3, "a{bdc}efg", testTitles3).equals("True,True,False"));
    }
}
